package com.andy.note.main.model.proxy.demo1;
 
 
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
 
/*
 *Created by William on 2018/8/12 0012
 */
public class DynaProxyHello implements InvocationHandler {
    private Object target;//目标对象
    /**
     * 通过反射来实例化目标对象
     * @param object
     * @return
     */
    public Object bind(Object object){
        this.target = object;
        return Proxy.newProxyInstance(this.target.getClass().getClassLoader(),
                this.target.getClass().getInterfaces(),this);
    }
 
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        Object result = null;
        System.out.println("=== start ===");
        result = method.invoke(this.target, args);
        System.out.println("=== end ===");
        return result;
    }
 
 
}